<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<title>${title}</title>
<%@include file="/WEB-INF/templates/common/common.jsp"%>
<style>
	td{border:1px solid red;text-align:center}
#div_TC {
	width: 940px;
	height: auto;
	background: #FFF;
	border-radius: 5px;
	margin: 0 auto;
	overflow: hidden;
	display: none;
}

.TC_title {
	width: 100%;
	height: 50px;
	background: #009388;
}

.TC_title h3 {
	font-family: "΢���ź�";
	font-size: 14px;
	color: #fff;
	font-weight: bold;
	line-height: 50px;
	text-indent: 32px;
	float: left;
}

.TC_title ul {
	width: 80px;
	height: 32px;
	float: right;
	margin-top: 9px;
}

.TC_title ul li {
	width: 76px;
	height: 32px;
	font-family: "΢���ź�";
	font-size: 14px;
	color: #030000;
	line-height: 32px;
	text-align: center;
	border: 0;
	background: url(${basePath}/static/scan/publics/images/but.png)
		no-repeat;
	float: left;
	margin-right: 14px;
}

.TC_title ul li input {
	cursor: pointer;
	display: block;
	width: 100%;
	height: 100%;
	font-size: 14px;
}

.TC_search_table {
	width: 936px;
	height:502px
	border: #e3e5e4 1px solid;
}

.TC_search_table li {
	float: left;
}

.TC_li {
	background: url(../../publics/images/sidebar2-2.png) no-repeat;
	margin-bottom: 4px;
	float: left;
}

.TC_current {
	color: #6c6f6f;
	background: url(../../publics/images/sidebar2-1.png) no-repeat;
}

.TC_foot {
	width: 100%;
	height: 54px;
	background: #009388;
	float: left;
}

.TC_foot ul {
	width: 100%;
	height: 32px;
	float: right;
	margin-top: 11px;
}

.TC_foot ul li {
	margin: 0 auto;
/* 	width: 172px; */
	height: 32px;
	font-family: "微软雅黑";
	font-size: 14px;
	color: #ffffff;
	line-height: 32px;
 	text-align: right; 
	border: 0;
}


#div_TC tr:nth-of-type(2n) .tdLabel_8 {
	background-color: #F5F5F5;
}

#div_TC tr td {
	border: 1px solid #D5DDDD;
}
.changeBorderStyle{
	border:1px red solid; 
}
.imgCla{
	display:inline-block;
	float:left;
	border:1px solid red;
	margin-left:3%;
	margin-top:2%
}

.clear{clear:both}
.btn{padding:4px 10px;}
</style>
<script type="text/javascript" src="${basePath}/static/page/js/jqPaginator.js"></script>
<script type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script  type="text/javascript" src="${basePath}/static/js/util.js"></script>

<script type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet"
	type="text/css">
<!-- <script  type="text/javascript" src="${basePath}/static/print/js/photo.js"></script> -->
<script type="text/javascript" src="${basePath}/static/js/ajaxfileupload.js"></script>
</head>
<body>

</head>
<body>
 <!--头部-->
 <%@include file="/WEB-INF/templates/common/header.jsp"%>

<!------导航条-->
 <%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<div class="list_main lay_out">
 <div class="list_DH">
    <!--打印模块导航栏-->
 <%@include file="/WEB-INF/templates/common/printnav.jsp"%>
 </div>
 <div class="list_NR">
  <div class="loc">
   <h3>打印登记</h3><div style="float:right">
   <font style="font-size:14px;color:#ff6600;font-weight:700;" id="isPrint">未打印</font> &nbsp;&nbsp;<div style="float:right;font-size:14px;color:#ff6600;font-weight:700;" id="pringCheck"></div>&nbsp;</div>
  </div>
 
  <div class="list_con_table"> 
   <div class="search_table">
   
    <ul id="table_ul">
    <input type="hidden" value="${basePath}" id="basePath"/>
    <input type="hidden" value="${picHostPath}" id="picHostPath"/>
   <form method="post" action="${basePath}/print/addPrintRecord" id="addPrintRecord" enctype="multipart/form-data">
    <input type="hidden" id="printApplyImageIds"  name="printApplyImageIds" value="">
    <input type="hidden" id="firstGuid" name="firstGuid" value="${hospitalNote.firstGuid}">
    <input type="hidden" id="printReason" name="printReason" value="${printReason}">
    <input type="hidden" name="onlyId" value="${hospitalNote.onlyId}">
    <li class="Label_1" >病案所属人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="40" name='name'  value='${hospitalNote.name}' readonly="readonly" style="background-color: #D3D3D3;" /></li>
    <li class="Label_1" >ID号：</li>
    <li class="Label_2"><input class="input_box" type="text"  maxlength="60" name='mrId'  value='${hospitalNote.mrId}' readonly="readonly" style="background-color: #D3D3D3;"/></li>
     <li class="Label_1">身份证：</li>
    <li class="Label_2"> 
    	<input class="input_box" type="text" maxlength="40" name='idCard'  value='${hospitalNote.idNumber}' readonly="readonly" style="background-color: #D3D3D3;"/>
     </li>
    <%--  <li class="Label_1" style="width:15%">操作人：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="40" name='operator'  value='${operator}' readonly="readonly" style="background-color: #D3D3D3;"/></li> --%>
    <li class="Label_1" >出院时间：</li>
    <li class="Label_2"><input type="text"   name="outTime" value="<fmt:formatDate value="${hospitalNote.outHospitalDate}" pattern="yyyy-MM-dd hh:mm" />"
					class="input_box" readonly="readonly" style="background-color: #D3D3D3;"/></li>
     <li class="Label_1">打印页数：</li>
    <li class="Label_2"> 
    	<input class="input_box" type="text" maxlength="40" name='printNum'  value='${printSize}' />
     </li>
      <li class="Label_1" >申请人：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="40" id='applyMan' name='applyMan'  value='' title=''/></li>
    <li class="Label_1" >申请人身份证：</li>
    <li class="Label_2"><input type="text" id='applyCard'  name="applyCard" value=""
					class="input_box" title=''/></li>
     <li class="Label_1">申请人联系方式：</li>
    <li class="Label_2"> 
    	<input class="input_box" type="text" maxlength="40" id='applyLinkway' name='applyLinkway'  value='' title=''/>
     </li>
     <%--  <li class="Label_1" style="width:15%">申请人地址：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="40" name='operator'  value='${operator}' /></li> --%>
    <li class="Label_1">申请人和病人关系：</li>
   <%-- ${relationList } --%>
   	<li class="Label_2">
		<select class="input_box" name="applyPatientRelation">
			<option value="本人">本人</option>
			<c:forEach items="${relationList}" var="relation">
				<option value="${relation.name }">${relation.name}</option>
			</c:forEach>
		</select>
	</li>
	<input type="hidden" name="applyReason" value='${applyReason}'/>
    <%--  <li class="Label_1">申请原因：</li>
    <li class="Label_2"> 
    	<input class="input_box" type="text" maxlength="40" name='applyReason'  value='${applyReason}'  readonly="readonly" style="background-color: #D3D3D3;"/>
     </li> --%>
     
     <input type="file" onchange="personPhoUpload()" id="personPho" name="file" style="display: none;">
    
    <li class="Label_5">
	   <a onclick="addPrintRecord()" style="width:auto;">保存登记信息</a>
	   <!-- <a id="Edit">拍照</a> -->
	   <a id="javascript:void(0)" onclick="$('#personPho').click()">上传</a>
       <a target="_blank" href="${basePath}/print/printToPageinfo?visitGuid=${hospitalNote.firstGuid}&applyReason=${printReason}">打印</a>
    </li>
    </form>
    </ul>
	 <div id="personImg" >
     	
     </div>
  </div>
  
 </div>
  <div id="imgContent" style="width:100%;margin-top:20%;" >
  	<%-- <img class='imgCla' imgId="1" width="30%" src="${basePath}/static/print/imgs/000077.png">
 	<img class='imgCla' imgId="2" width="30%" src="${basePath}/static/print/imgs/000077.png">
  		<img class='imgCla' imgId="3" width="30%" src="${basePath}/static/print/imgs/000077.png">
 	<img class='imgCla' imgId="4" width="30%" src="${basePath}/static/print/imgs/000077.png">
 		<img class='imgCla' imgId="5" width="30%" src="${basePath}/static/print/imgs/000077.png">
 	<img class='imgCla' imgId="6" width="30%" src="${basePath}/static/print/imgs/000077.png">  --%>
  </div>
</div>

</div>

<!-- 新增弹出框-->
	<div id="div_TC">
		<div class="TC_title">
			<h3>拍照</h3>
			<ul>
				<li><a class="int"id="closeBtn2">取消</a></li>
			</ul>
		</div>
		<div class="TC_search_table">
			<div style="float:left;width: 598px; height: 500px;border:1px solid green">
				<object 
					type="application/x-itst-activex" 
					classid="clsid:454C18E2-8B7D-43C6-8C17-B1825B49D7DE"
					id="captrue"
					width="598" 
					height="500"></object>
			</div>
			<div style="border:1px solid red;width:336px;height:500px;float:right;overflow:auto">

			    <div id="picDiv" style="width:300px;height:400px;margin:50px auto;border:1px solid yellow">
			    	
			    </div>
			
			</div>
			<div style="clear:both"></div>
	   </div>
		 
		<div class="TC_foot">
			<ul>
				<li style="width:100%;text-align:center;color:#333">
				
  <input type="button" class="btn" value="停止" name="StopBtn" onClick="CAPTURE.closeCaptrue()">
  <input type="button" class="btn" value="拍摄" name="SaveJPGBtn" onClick="photoImg()">
  <input type="button" class="btn" value="参数设置" name="ParaSet" onClick="CAPTURE.paramSetting()">
  <input type="button" class="btn" value="PIN设置" name="ParaSet" onClick="CAPTURE.pinSetting()">

 亮度: <select onChange="CAPTURE.brightnessSetting(this)">
 	<option value="-64">-64</option>
	<option value="-60">-60</option>
	<option value="-50">-50</option>
	<option value="-40">-40</option>
	<option value="-30">-30</option>
	<option value="-20">-20</option>
	<option value="-10">-10</option>
	<option value="0">0</option>
	<option value="10">10</option>
	<option value="20" selected="selected">20</option>
	<option value="30">30</option>
	<option value="40">40</option>
	<option value="50" >50</option>
	<option value="60">60</option>
	<option value="64">64</option>

  </select>

  对比度: <select onChange="CAPTURE.contrastSetting(this)">
	<option value="0">0</option>
	<option value="10">10</option>
	<option value="20" selected="selected">20</option>
	<option value="30">30</option>
	<option value="40">40</option>
	<option value="50">50</option>
	<option value="60">60</option>
	<option value="70">70</option>
	<option value="80">80</option>
	<option value="90">90</option>
	<option value="95">95</option>
  </select>
  曝光度:
  <select id="ExposureValue" onChange="CAPTURE.sensitometrySetting(this)">
	<option value="0">0</option>
	<option value="10">10</option>
	<option value="20">20</option>
	<option value="30">30</option>
	<option value="40">40</option>
	<option value="50" selected="selected">50</option>
	<option value="60">60</option>
	<option value="70">70</option>
	<option value="80">80</option>
	<option value="90">90</option>
	<option value="100">100</option>
  </select>
  
  <input type="button" class="btn" value="旋转" onClick="CAPTURE.rotate()">&nbsp;
  
    拍摄类型:
  <select id="photoType" onChange="CAPTURE.photoType(this)">
	<option value="3">自动</option>
	<option value="0">默认</option>
	<option value="4">证件</option>
	<option value="1">自定义</option>
  </select>&nbsp;
  <input type="button" class="btn" value="删除" onClick="deleteImg()">&nbsp;
    <input type="button" class="btn" value="保存" onClick="savePhotoImage()">&nbsp;
  
	
				</li>
			</ul>
		</div>
	</div>
<!--页脚部分-->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>
 <script>
 
   $(function(){
	   isPrint();
	   isCheck();
   })
   
   function isCheck(){
	   var firstGuid = $("#firstGuid").val();
		  $.ajax({
			  type:"post",
			  data:{firstGuid:firstGuid},
			  url:"${basePath}/print/selectPrintCheckByGuid",
			  success:function(data){
				if(data=="" || data.status==1){
					$("#pringCheck").html("<a onclick='printCheck()' class='int'>审核</a>&nbsp;&nbsp;");
				}else{
					$("#pringCheck").html("已审核 &nbsp;&nbsp;")
				}
			  }
		  })
   }
   
   
   function printCheck(){
	   var firstGuid = $("#firstGuid").val();
		  $.ajax({
			  type:"post",
			  data:{firstGuid:firstGuid},
			  url:"${basePath}/print/printCheckByGuid",
			  success:function(data){
				  //alert(JSON.stringify(data));
				if(data > 0){
					$("#pringCheck").html("已审核 &nbsp;&nbsp;")
				}
			  }
		  })
   }
   
 
 	function personPhoUpload() {
 		ajaxFileUpload();
 	}
 	
	function imgDelete(event) {
		var $target = $(event.target);
		//alert($target.parents('.d_img').html());
		$target.closest(".d_img").remove();
	}

	//上传图片
	function ajaxFileUpload() {  
	    $.ajaxFileUpload({  
	        url: '${basePath}/upload/tempUploadFile', //服务器端请求地址  ,
	        secureuri: false, //是否需要安全协议，一般设置为false  
	        fileElementId: 'personPho', //文件上传域的ID  
	        dataType: 'json', //返回值类型 一般设置为json  
	        enctype:'multipart/form-data',//注意一定要有该参数  
	        success: function (result)  //服务器成功响应处理函数  
	        {  
	        	$("#personPho").val("");
	        	console.log(result)
	            if(result.success){      //data是从服务器返回来的值 
				//alert(${basePath}+"/"+result.data.printRegisterUploadPicPath + "/" + result.data.filePath);	            	
	             var imgContext = "";
	             imgContext+="<div style='float:left; position: relative;' class='d_img'>";
	             var filePath = result.data.printRegisterUploadPicPath + '/' + result.data.filePath;
	    		 imgContext+="<img width='200' height='200'  filePath="+result.data.filePath+" style='padding:5px; ' src="+filePath+" class='imgs'>";
	    		 imgContext+="<img src='${basePath}/static/images/delete.png' width='20' height='20' style='position:absolute; top:5px; right:5px;' onclick='imgDelete(event)'>";
	    		 imgContext+="</div>";
	    		 $("#personImg").append(imgContext);
	            } 
	        },  
	        error: function (data, status, e)//服务器响应失败处理函数  
	        {  
	            alert("服务器错误，请稍后再试");
	            $("#personPho").val("");
	        }  
	    })  
	};
	
	
	function addPrintRecord(){
		 var imgPaths = "";
		 for (var i = 0; i < $(".imgs").length; i++) {
			 var $img = $(".imgs")[i];
			 imgPaths += $img.getAttribute("filePath") +",";
		 }
	    
		 if (imgPaths != null && imgPaths != "") {
			 imgPaths = imgPaths.substring(0, imgPaths.length-1);
		 }	  
		  
		/*  var imgIds=[];
		 $(".imgCla").each(function(){
			 imgIds.push($(this).attr("imgId"));
		 })
		 $("#printApplyImageIds").val(imgIds); */
		 
		 $("#printApplyImageIds").val(imgPaths);
		 
		 var applyMan=$("#applyMan").val();
		 var applyCard=$("#applyCard").val();
		 var applyLinkway=$("#applyLinkway").val();
		/*  if(applyMan=='' || applyCard=='' || applyLinkway==''){
			 layer.alert('输入框不能为空!',{icon:0});
			 $("[title='']").each(function(){
				 $("[title='']").addClass('changeBorderStyle');
			 });
			
			 return;
		 } */

		 $("#addPrintRecord").submit();
	 }
 
  $('#Edit').on("click", function() {
		easyDialog.open({
			container : 'div_TC',
			fixed : true,
		});
		//开启摄像头
		CAPTURE.openMainCaptrue();
		
		
	}); 
  
  $('#closeBtn2').on("click", function() {
	    //关闭弹框
	    easyDialog.close();
		//关闭摄像头
		CAPTURE.closeCaptrue();
		
	})
	
	
	function isPrint(){
	  var firstGuid = $("#firstGuid").val();
	  $.ajax({
		  type:"post",
		  data:{firstGuid:firstGuid},
		  url:"${basePath}/print/selectPrintNumByGuid",
		  success:function(data){
			 if(data==0){
				 $("#isPrint").html("未打印");
			 }else{
				 $("#isPrint").html("已打印"+data+"次"); 
			 }
		  }
	  })
    }

 
 
  
  
 $("input,select").focus(function() { 
		$("[title='']").each(function() {
	  		$("[title='']").removeClass("changeBorderStyle");
		});
 });
 
//拍摄图片
 function photoImg(){
 	$("#picDiv").html("");
 	//删除临时文件夹
 	CAPTURE.deletePhotoImg();
 	//初始化默认信息
 	CAPTURE.init();
 	//拍摄图片返回文件名
 	var fileName = CAPTURE.photoJPSImg();
 	//var picHostPath="http://localhost:8090/upload/temp/";
 	//alert($("#photoType").val());
 	var photoType=$("#photoType").val();
 	//拍摄类型为证件第一次拍摄为一部分不进行上传，第二次进行上传
 	if(photoType==4){
 		if(CAPTURE.photoCount==1){
 			return;
 		}else{
 			CAPTURE.photoCount=0;
 		}
 	};

 	var filePath=CAPTURE.tempPath+fileName+".jpg";
 	

 	var result= uploadPhotoImg(filePath);
 	if(result.ret=="success"){
 		var hostFileName=result.fileName;
 		var hostFileUrl=result.fileUrl;
 		//alert(hostFileUrl+hostFileName);
 		var picHostPath=$("#picHostPath").val();
 		var fileUrl=picHostPath+hostFileUrl+hostFileName;
 		//alert(fileUrl);
 		var html="<img width='300' id='img' fileUrl='"+hostFileUrl+"'  fileName='"+hostFileName+"' height='400' src='"+fileUrl+"'/>";
 		$("#picDiv").html(html);
 	}
 	
 	
 }
 
//拍照
 var CAPTURE = {
 		tempPath:"D:\\MRLOCAL\\",
 		//拍摄次数
 		photoCount:0,
 		//开启摄像头
 		openMainCaptrue:function(){
 			  captrue.bStopPlay(); 
 		      captrue.vSetResolution(7);
 				    	
 		      captrue.bStartPlay();
 			  captrue.bSetMode(3); 
 		},
 		//关闭摄像头
 		closeCaptrue:function(){
 			captrue.bStopPlay();
 		},
 		//拍摄jsp格式图片
 		photoJPSImg:function(){
 			var fileName = new Date().getTime();
 			captrue.bSaveJPG(this.tempPath,fileName);
 			if($("#photoType").val()==4){
 				this.photoCount++;
 			};
 			return fileName;
 		},
 		init:function(){
 			//切黑边
 			captrue.vSetDelHBFlag(1);
 			//设置矫正
 			captrue.vSetSkewFlag(1);
 		},
 		//参数设置
 		paramSetting:function(){
 			captrue.displayVideoPara();
 		},
 		//PIN设置
 		pinSetting:function(){
 			captrue.vSetCapturePin();
 	  		captrue.bStartPlay2(0);
 		},
 		//删除拍摄图片
 		deletePhotoImg:function(){
 			var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
 			var fileSystem = fileSystemObject.GetFolder(this.tempPath);
 			var enumFiles = new Enumerator(fileSystem.files);
 			for (; !enumFiles.atEnd(); enumFiles.moveNext()) {
 				enumFiles.item().Delete();
 			}
 		},
 		//设置亮度
 		brightnessSetting:function(element){
 			
 			captrue.vSetBrightness(element.value);
 		},
 		//对比度
 		contrastSetting:function(element){
 			
 			captrue.vSetContrast(element.value);
 		},
 		//设置曝光度
 		sensitometrySetting:function(element){
 			
 			captrue.vSetExposure(element.value);
 		},
 		rotate:function(){
 			  captrue.bStopPlay();  	
 			  if(this.rotateAngle==360){
 				  this.rotateAngle=0;
 			  }
 		      captrue.bStartPlayRotate(this.rotateAngle);
 		      this.rotateAngle=this.rotateAngle+90;
 		      
 		},
 		//每次旋转角度
 		rotateAngle:90,
 		//拍摄类型
 		photoType:function(element){
 			if(element.value==1){
 	 				captrue.bSetImageArea(1000,1000,8000,8000);
 			}
 			captrue.bSetMode(element.value);
 		}
 		
 } 
 
	//上传图片
	function savePhotoImage(){
		var fileName=$("#img").attr("fileName");
		var fileUrl=$("#img").attr("fileUrl");
		if(!fileName && !fileUrl){
			alert("拍摄图片路径为空!请重新拍摄!");
			return;
		}
		
		$.ajax({
			type:"post",
			url:"${basePath}/print/addPhotoImg",
			data:{filePath:fileUrl,fileName:fileName},
			success:function(data){
				console.log(data);
			
				 if(data.success){
					 var picHostPath=$("#picHostPath").val();
					$("#picDiv").html("");
					var printapplyImg=data.data;
					var url=picHostPath+printapplyImg.filePath+printapplyImg.fileName;
					//layer.msg("拍摄图片保存成功!",{icon:1});
					var html="<img class='imgCla' width='30%' imgId='"+printapplyImg.id+"' src='"+url+"'>";
					$("#imgContent").append(html);
				 }else{
					 alert(data.msg);
				 }
			}
		});
	}
	
	//删除图片
	function deleteImg(){
		$("#picDiv").html("");
	}

 
/*  window.onload = function(){
	 var medicalOnlyId=$("#firstGuid").val();
	 var applyReason=$("#printReason").val();
	 openPrint(medicalOnlyId,applyReason);
 } */

 	
/*  	function openPrint(medicalOnlyId,applyReason){
  		window.open("${basePath}/print/printPic?medicalOnlyId="+medicalOnlyId+"&applyReason="+applyReason+"",
 				'_blank',
 				"toolbar=yes,resizable=1, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width=800, height=600"); 
 	} */
	
 </script>

</body>
</html>
